<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title></title>
	<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/mui.min.js"></script>
	<script src="js/app.js"></script>
    <link href="css/mui.min.css" rel="stylesheet"/>

</head>
<body>
	<header class="mui-bar mui-bar-nav">
		<h1 class="mui-title">登录/注册</h1>
	</header>
	<div class="mui-content" style="margin-top: 200px;">
		<form id='login-form' class="mui-input-group">
			<div class="mui-input-row">
				<label>账号</label>
				<input id='account' type="text" class="mui-input-clear mui-input" placeholder="请输入账号">
			</div>
			<div class="mui-input-row" >
				<label>密码</label>
				<input id='password' type="password" class="mui-input-clear mui-input" placeholder="请输入密码">
			</div>
			 <div class="mui-input-row">
				<label>验证码</label>
				<input id='imgCode' type="text" class="mui-input-clear mui-input"  placeholder="点击下方获取验证码">
			</div> 
			 <div class="mui-input-row" id="gimg" style="text-align: center;background-color: rgb(232, 240, 254);">
				
				<div style="margin-top: 10px;" id="dianji">点击此处：</div><img src=""  id="getImgCode" style="height: 37px;margin-top: -8px;">
			</div> 
			
		</form>
		<div class="mui-content-padded" style="margin-top: 20px;">
			
			<button id='login' class="mui-btn mui-btn-block mui-btn-primary">登录</button>
			<div class="link-area"><a id='reg'>注册</a> <span class="spliter"><!-- |</span> <a id='forgetPassword'>忘记密码</a> -->
			</div>
		</div>

	</div>
	
	
	<script type="text/javascript" charset="utf-8">
	  (function($, doc) {
		  
		
		  $.init({
	  		statusBarBackground: '#f7f7f7'
		
	  	});
		//检查 "登录状态/锁屏状态" 结束
		var loginButton = doc.getElementById('login');
		var accountBox = doc.getElementById('account');
		var passwordBox = doc.getElementById('password');
		var regButton = doc.getElementById('reg');
		var imgCode = doc.getElementById('imgCode');
		var getImgCode = doc.getElementById('getImgCode');
		var gimgButton = doc.getElementById('gimg');
		regButton.addEventListener('tap',function(){
			console.log(loginButton.value)
			if(loginButton.innerHTML=="注册"){
				loginButton.innerHTML="登录"
				regButton.innerHTML="注册"
			}else{
				loginButton.innerHTML="注册"
				regButton.innerHTML="登录"
			}
		});
		var forgetButton = doc.getElementById('forgetPassword');
		accountBox.value="";
		passwordBox.value="";
		gimgButton.addEventListener('tap', function(event) {
			console.log("sds");
			var mobile=accountBox.value;
			    	if(mobile==""){
			    		 $.toast("请输入用户名");
			    		return;
			    	} 
					
					doc.getElementById("dianji").textContent='';
			    	doc.getElementById("getImgCode").src=api+"/other/getImgCode?telephone="+mobile+"&time="+new Date()/1000;
				
		});
		loginButton.addEventListener('tap', function(event) {
			if(!accountBox.value){
				$.toast("请输入帐号")
				return ;
			}
			if(!passwordBox.value){
				$.toast("请输入密码")
				return ;
			}
			if(!imgCode.value){
				$.toast("请输入验证码")
				return ;
			}
			if(loginButton.innerHTML=="登录"){
				console.log("login")
				login();
			}
			if(loginButton.innerHTML=="注册"){
				console.log("regist")
				regist();
			}
			
			
			
		});
		function login(){
			$.ajax(api+'/user/login',{
				data:{
					mobile:accountBox.value,
					password:passwordBox.value,
					imgCode:imgCode.value
				},
				crossDomain:true,
				type:'post',//HTTP请求类型
				sslVerify: false,
				timeout:10000,//超时时间设置为10秒；data
				// headers:{'Content-Type':'application/'},	              
				success:function(data){
					if(data.code==1){
						$.toast("登录成功")
						localStorage.setItem("userinfo",JSON.stringify(data.data))
						setTimeout(function () {
							location.href='index.html';
						},200);
					}else{
						$.toast(data.msg)
					}
					
				},
				error:function(xhr,type,errorThrown){
					alert(type)
					//异常处理；
					console.log(type);
				}
			});
		}
		function regist(){
			$.ajax(api+'/user/register',{
				data:{
					mobile:accountBox.value,
					password:passwordBox.value,
					pid:1000,
					imgCode:imgCode.value
				},
				dataType:'json',//服务器返回json格式数据
				crossDomain:true,
				type:'post',//HTTP请求类型
				timeout:10000,//超时时间设置为10秒；data
				headers:{'Content-Type':'application/json'},
								  
				success:function(data){
					if(data.code==1){
						$.toast("注册成功")
						localStorage.setItem("userinfo",JSON.stringify(data.data))
						setTimeout(function () {
							location.href='login1.html';
						},200);
					}else{
						$.toast(data.msg)
						setTimeout(function () {
							location.href='login1.html';
						},200);
					}
					
				},
				error:function(xhr,type,errorThrown){
					alert(type)
					//异常处理；
					console.log(type);
				}
			});
		}
	  }(mui, document));
	</script>
</body>
</html>